package com.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by mayufeng on 2017/5/15.
 * 时间工具类
 */
public class DataUtils {

    public static SimpleDateFormat getSimpleDateFormat(){
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    }

    /**
     * 字符串转时间
     * @param date
     * @return
     */
    public static Date StringToDate(String date){
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd HH:mm:ss");
        try {
            return  format.parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 时间转字符串
     * @param date
     * @return
     */
    public static String dateToString(Date date){
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return  format.format(date);
    }
}
